package com.yiyuan.app.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.guaike.core.mybatis.plugins.BaseDAO;
import com.yiyuan.app.entity.enums.OrderProductTypeEnum;
import com.yiyuan.app.entity.po.DOrderRechargePO;
import com.yiyuan.app.mapper.DOrderRechargeExtMapper;
import com.yiyuan.app.mapper.DOrderRechargeMapper;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Repository;

@Repository
@AllArgsConstructor
public class DOrderRechargeDAO extends BaseDAO<DOrderRechargeMapper, DOrderRechargePO> {

    private DOrderRechargeExtMapper orderRechargeExtMapper;

    public DOrderRechargePO findNoviceGiftPack(Long userId, Integer status) {
        LambdaQueryWrapper<DOrderRechargePO> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(DOrderRechargePO::getUserId, userId);
        queryWrapper.eq(DOrderRechargePO::getProductType, OrderProductTypeEnum.novice_gift_pack.getCode());
        queryWrapper.eq(DOrderRechargePO::getStatus, status);
        return getBaseMapper().selectOne(queryWrapper);
    }

    public DOrderRechargePO findByOrderNumberLock(String orderNumber) {
        return orderRechargeExtMapper.findByOrderNumberLock(orderNumber);
    }

    public DOrderRechargePO findByRefundOrderNumberLock(String refundOrderNumber) {
        return orderRechargeExtMapper.findByRefundOrderNumberLock(refundOrderNumber);
    }
}
